package cn.hg.jfsa.config;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.jfinal.plugin.druid.IDruidStatViewAuth;

import cn.hg.jfsa.core.SessionThreadLocal;
import cn.hg.jfsa.model.JfsaAdmin;
import cn.hg.jfsa.model.JfsaResource;

public class JfsaDruidStatViewAuth implements IDruidStatViewAuth {
	private String actionKey;

	public JfsaDruidStatViewAuth(String actionKey){
		this.actionKey = actionKey;
	}

	@Override
	public boolean isPermitted(HttpServletRequest request) {
		JfsaAdmin currAdmin = SessionThreadLocal.getAdmin();
		if (null != currAdmin) {
			if (currAdmin.getId() == 1) {
				return true;
			}
			Map<String, JfsaResource> actionMap = SessionThreadLocal.getAdminAuthAction();

			JfsaResource action = actionMap.get(this.actionKey);
			if (action != null) {
				return true;
			}

			return actionMap.containsKey(actionKey);
		}

		return false;
	}
}
